package com.edfapp.costom;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;

/**
 * @author hong
 * @description 描述
 * @time 2025/9/18 17:34
 **/
public class ValidateEdfHeader {
    public static void main(String[] args) throws Exception {
        File f = new File("C:\\Users\\xinho\\Desktop\\hello.edf");
        try (RandomAccessFile r = new RandomAccessFile(f, "r")) {
            byte[] head = new byte[256];
            r.readFully(head);
            // 1. 版本号 8 字节
            System.out.println("version : " + new String(head, 0, 8, StandardCharsets.US_ASCII) +
                    " | len=" + head[7] + " (expect 32=space)");
            // 2. 用户 80 字节
            System.out.println("patient : " + new String(head, 8, 80, StandardCharsets.US_ASCII).trim() +
                    " | bytes 88-95=[" +
                    new String(head, 88, 8, StandardCharsets.US_ASCII) + "]");
            // 3. 记录信息 80 字节
            System.out.println("record  : " + new String(head, 88, 80, StandardCharsets.US_ASCII).trim());
            // 4. 日期 8 字节
            System.out.println("date    : " + new String(head, 168, 8, StandardCharsets.US_ASCII));
            // 5. 时间 8 字节
            System.out.println("time    : " + new String(head, 176, 8, StandardCharsets.US_ASCII));
            // 6. 头字节数 8 字节
            System.out.println("bytes   : " + new String(head, 184, 8, StandardCharsets.US_ASCII));
            // 7. 记录条数 8 字节
            System.out.println("records : " + new String(head, 236, 8, StandardCharsets.US_ASCII));
            // 8. 通道数 4 字节
            System.out.println("signals: " + new String(head, 252, 4, StandardCharsets.US_ASCII));
        }
    }
}
